﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Net;
using System.Xml;

namespace DispatchAssist.AppHost
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            #region check and download new version program

            //bool bHasError = false;
            //IAutoUpdater autoUpdater = new AutoUpdater();
            //try
            //{
            //    autoUpdater.Update();
            //}
            //catch (WebException exp)
            //{
            //    MessageBox.Show("Can not find the specified resource");
            //    bHasError = true;
            //}
            //catch (XmlException exp)
            //{
            //    bHasError = true;
            //    MessageBox.Show("Download the upgrade file error");
            //}
            //catch (NotSupportedException exp)
            //{
            //    bHasError = true;
            //    MessageBox.Show("Upgrade address configuration error");
            //}
            //catch (ArgumentException exp)
            //{
            //    bHasError = true;
            //    MessageBox.Show("Download the upgrade file error");
            //}
            //catch (Exception exp)
            //{
            //    bHasError = true;
            //    MessageBox.Show("An error occurred during the upgrade process");
            //}
            //finally
            //{
            //    if (bHasError == true)
            //    {
            //        try
            //        {
            //            autoUpdater.RollBack();
            //        }
            //        catch (Exception)
            //        {
            //            //Log the message to your file or database
            //        }
            //    }
            //}

            #endregion

            var updater = FSLib.App.SimpleUpdater.Updater.Instance;

            updater.Error += new EventHandler(updater_Error);
            updater.NoUpdatesFound += new EventHandler(updater_NoUpdatesFound);
            updater.UpdatesFound += new EventHandler(updater_UpdatesFound);
            
            FSLib.App.SimpleUpdater.Updater.CheckUpdateSimple("http://172.17.64.117/ClientUpdate/update.xml");

            Application.Run(new frmLogin());
        }

        static void updater_UpdatesFound(object sender, EventArgs e)
        {

        }

        static void updater_NoUpdatesFound(object sender, EventArgs e)
        {
            //System.Windows.Forms.MessageBox.Show("没有找到更新");
        }

        static void updater_Error(object sender, EventArgs e)
        {
            var updater = sender as FSLib.App.SimpleUpdater.Updater;
            System.Windows.Forms.MessageBox.Show(updater.Exception.ToString());
        }
    }
}
